<?php
/**
 * 新增部门
 *
 * @author Dracowyn
 * @since 2023-11-17 17:27
 */

// 引入配置文件
include_once('config/config.php');
$loginAuth = check_auth();

if ($_POST) {
	$name = trim($_POST['name']);
	if (empty($name)) {
		showMsg('部门名称不能为空');
		exit();
	}
	$sql = "SELECT name FROM pre_department WHERE name = '$name'";
	$findName = find($sql);
	if ($findName) {
		showMsg('部门名称已存在');
		exit();
	}
	$data = [
		'name' => $name,
	];
	$res = insert('department', $data);
	if ($res['code'] === 0) {
		showMsg($res['msg']);
	} else {
		showMsg('添加成功', 'depList.php');
	}
}

?>

<!DOCTYPE html>
<html lang="zh">
<head>
	<?php include_once('common/meta.php'); ?>
    <title>添加部门</title>
</head>

<body>

<?php include_once('common/header.php'); ?>

<?php include_once('common/menu.php'); ?>

<div class="content">
    <div class="header">
        <h1 class="page-title">添加部门</h1>
    </div>
    <ul class="breadcrumb">
        <li><a href="index.php">首页</a> <span class="divider">/</span></li>
        <li><a href="depList.php">部门管理</a> <span class="divider">/</span></li>
        <li class="active">添加部门</li>
    </ul>

    <div class="container-fluid">
        <div class="row-fluid">

            <div class="btn-toolbar">
                <button class="btn btn-primary" onClick="location='depList.php'"><i class="icon-list"></i>部门列表
                </button>
                <div class="btn-group">
                </div>
            </div>

            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <form method="post" enctype="multipart/form-data">
                            <label for="name">部门名称</label>
                            <input type="text" name="name" id="name" class="input-xxlarge"
                                   placeholder="请输入部门名称">
                            <label></label>
                            <input class="btn btn-primary" type="submit" value="提交"/>
                        </form>
                    </div>
                </div>
            </div>
			<?php include_once('common/footer.php'); ?>
        </div>
    </div>
</div>
</body>
<?php include_once('common/script.php'); ?>
</html>
